<?php

include '../../../configuration.php';

$category = $_POST['category'];
$complexity = $_POST['complexity'];
$question= $_POST['question'];
$choices = array();
for ($j = 0; $j < 4; $j++) {
	$choices[] = $_POST['choice'.$j];
}
$answer = $_POST['radio'];
$udate = $_POST['udate'];
$cdate = $_POST['cdate'];

$result = mysql_query("SELECT * FROM categories WHERE cat_title='$category'");
$rows = mysql_fetch_assoc($result);
$category_id = $rows["cat_id"];

mysql_query("INSERT INTO questions (q_id, q_title, cat_id, q_complexity, q_cdate, q_udate) VALUES (null, '$question', '$category_id', '$complexity', now(), now())");
$q_id = mysql_insert_id();

$hold_answer = 0;
for ($j = 0; $j < 4; $j++) {
	if ($j == $answer) $hold_answer = 1;
	/* echo "<br>".$j." ".$hold_answer;
	echo "<br>"."INSERT INTO choices (c_id, q_id, c_title, c_order, c_correctvalue, cdate, udate) VALUES (null, '$q_id', '$choices[$j]', $j+1, '$hold_answer', '$cdate','$udate')"; */
	mysql_query("INSERT INTO `choices` (`c_id`, `q_id`, `c_title`, `c_order`, `c_correctvalue`, `cdate`, `udate`) VALUES (null, '$q_id', '$choices[$j]', $j+1, '$hold_answer', now(),now())");
	$hold_answer = 0;
}
header ("Location: insert_question.php");
?>
